package com.piggy.logi.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.bo.LogiWaybillPayableQueryBo;
import com.piggy.logi.sys.bo.LogiWaybillPayableRecordEditBo;
import com.piggy.logi.sys.domain.LogiWaybillPayableRecord;
import com.piggy.logi.sys.service.ILogiWaybillPayableService;
import com.piggy.logi.sys.vo.LogiWaybillPayableVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 应付管理Controller
 *
 * @author fengxy
 * @date 2023/10/17 21:28
 **/
@Api(value = "应付管理控制器", tags = {"应付管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/waybill/payable")
public class LogiWaybillPayableController extends BaseController {

    private final ILogiWaybillPayableService iLogiWaybillPayableService;

    /**
     * 查询应付列表
     */
    @ApiOperation("查询应付列表")
    //@SaCheckPermission("sys:waybill:payable:list")
    @PostMapping("/list")
    public TableDataInfo<LogiWaybillPayableVo> list(@Validated @RequestBody LogiWaybillPayableQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiWaybillPayableService.queryPageList(bo);
    }

    /**
     * 获取应付详情
     */
    @ApiOperation("获取应付详情")
    //@SaCheckPermission("sys:waybill:payable:query")
    @GetMapping("/{id}")
    public R<LogiWaybillPayableVo> queryById(@NotNull(message = "id不能为空") @PathVariable("id") Long id) {
        return R.ok(iLogiWaybillPayableService.queryById(id));
    }

    /**
     * 确认付款
     **/
    @ApiOperation("确认付款")
    //@SaCheckPermission("sys:waybill:payable:confirmPay")
    @LogiLog(title = "应付管理", businessType = BusinessType.INSERT)
    @PostMapping("/confirmPay")
    public R<Object> confirmPay(@Validated @RequestBody LogiWaybillPayableRecordEditBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        iLogiWaybillPayableService.confirmPay(bo);
        return R.ok();
    }

    /**
     * 查询付款记录
     */
    @ApiOperation("查询付款记录")
    //@SaCheckPermission("sys:waybill:payable:payList")
    @GetMapping("/payList/{id}")
    public R<List<LogiWaybillPayableRecord>> payList(@ApiParam(value = "应付记录Id") @NotNull(message = "应付记录id不能为空") @PathVariable(value = "id") Long id) {
        List<LogiWaybillPayableRecord> records = iLogiWaybillPayableService.payList(id);
        return R.ok(records);
    }

    /**
     * 修改付款记录
     **/
    @ApiOperation("修改付款记录")
    //@SaCheckPermission("sys:waybill:payable:updateRecord")
    @LogiLog(title = "应付管理", businessType = BusinessType.UPDATE)
    @PostMapping("/updateRecord")
    public R<Object> updateRecord(@Validated @RequestBody LogiWaybillPayableRecordEditBo bo) {
        iLogiWaybillPayableService.updateRecord(bo);
        return R.ok();
    }

    /**
     * 删除付款记录
     **/
    @ApiOperation("删除付款记录")
    //@SaCheckPermission("sys:waybill:payable:deleteRecord")
    @LogiLog(title = "应付管理", businessType = BusinessType.DELETE)
    @PostMapping("/deleteRecord/{id}")
    public R<Object> deleteRecord(@ApiParam(value = "付款记录Id") @NotNull(message = "付款记录id不能为空") @PathVariable(value = "id") Long id) {
        iLogiWaybillPayableService.deleteRecord(id);
        return R.ok();
    }

    /**
     * 确认结清
     **/
    @ApiOperation("确认结清")
    //@SaCheckPermission("sys:waybill:payable:confirmSettle")
    @LogiLog(title = "应付管理", businessType = BusinessType.UPDATE)
    @PostMapping("/confirmSettle/{id}")
    public R<Object> confirmSettle(@ApiParam(value = "应付记录Id") @NotNull(message = "应付记录id不能为空") @PathVariable(value = "id") Long id) {
        iLogiWaybillPayableService.confirmSettle(id);
        return R.ok();
    }

    /**
     * 取消结清
     **/
    @ApiOperation("取消结清")
    //@SaCheckPermission("sys:waybill:payable:cancelSettle")
    @LogiLog(title = "应付管理", businessType = BusinessType.UPDATE)
    @PostMapping("/cancelSettle/{id}")
    public R<Object> cancelSettle(@ApiParam(value = "应付记录Id") @NotNull(message = "应付记录id不能为空") @PathVariable(value = "id") Long id) {
        iLogiWaybillPayableService.cancelSettle(id);
        return R.ok();
    }
}
